package com.iyue;

import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.betwixt.io.BeanReader;
import org.xml.sax.SAXException;

import com.iyue.util.face.Face;
import com.iyue.util.face.FaceFactory;

/**
 * 《配置管理》实现类
 * 
 * @author 孙晓晔
 * @version $Id: Config.java,v 1.2 2011/01/05 09:35:29 fresh Exp $
 */
public class Config {
	/**
	 * 文件服务地址
	 */
	private String file;
	/**
	 * 图片缓存地址
	 */
	private String img;
	/**
	 * 表情
	 */
	private static List<Face> faces;
	/**
	 * 提示信息
	 */
	private Map<String, String> messages = new HashMap<String, String>();

	public Map<String, String> getMessages() {
		return messages;
	}

	public void setMessages(Map<String, String> messages) {
		this.messages = messages;
	}

	public List<Face> getFaces() {
		if (faces != null) {
			return faces;
		}

		FaceFactory ff = new FaceFactory();

		try {
			BeanReader read = new BeanReader();
			read.registerBeanClass(ff.getClass());
			InputStream in = getClass().getResourceAsStream("/cfg/face.xml");
			ff = (FaceFactory) read.parse(in);
		} catch (IntrospectionException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		}

		faces = ff.getFaces();

		return faces;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public String getFile() {
		return file;
	}

	public void setFile(String file) {
		this.file = file;
	}
}
